#!/bin/bash
# Copyright 2013 Google Inc.  All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License.  You may obtain a copy
# of the License at: http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distrib-
# uted under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied.  See the License for
# specific language governing permissions and limitations under the License.

# Sets up the 'gmail.test' domain and adds a map using MapRoot JSON from stdin.
# Prints out the ID of the newly created map, which is owned by root@gmail.test.
#
# Usage:
#
# tools/load_map :8000 < maproot.json  # load from file maproot.json
# echo '{"title":"foo"}' | tools/load_map :8000  # load from stdin

pushd "$(dirname $0)" >/dev/null && source common.sh && popd >/dev/null

export REMOTE_API_RC="
from pprint import *
from model import *
from perms import *
from maps import *
import sys, domains, users, test_utils, json
with test_utils.RootLogin(): domains.Domain.Put('gmail.test')
perms.Grant('root', perms.Role.DOMAIN_ADMIN, 'gmail.test')
print test_utils.CreateMap(json.loads(sys.stdin.read()), 'gmail.test').id
"
$PYTHON $TOOLS_DIR/remote_api.py "$@" -c pass
